package com.changgou.system.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;


@Component
public class UrlFilter implements GlobalFilter, Ordered {

    //需要拦截携带token的请求地址
    public static String filterPath="/api/wtemplate/**,/api/worder/**,/api/find/**,/api/page,/seytem/wbrand/**,,/seytem/findGoods/**,/seytem/worder/**,/seytem/wpara/**,/seytem/wreport/**,/seytem/findSKu/**,/seytem/wspec/**,/seytem/wtemplate/**";

    public static boolean hasAuthorize(String uri){
        String[] strs = filterPath.replace("/**", "").split(",");
        for (String str : strs) {
            if (uri.startsWith(str)){
                return true;
            }
        }
        return false;
    }
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("经过了第二个过滤器");
        String path = exchange.getRequest().getURI().getPath();
        System.out.println("path:"+path);
        //放行
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 2;
    }
}
